<template>
  <el-container class="container">
    <!-- 头部 -->
    <el-header>
      <el-row>
        <el-col :span="8"
          ><div class="grid-content bg-purple-dark">公司logo</div></el-col
        >
        <el-col :span="8"
          ><div class="grid-content bg-purple-dark">企业后台管理</div></el-col
        >
        <el-col :span="8"
          ><div class="grid-content bg-purple-dark">
            <el-button type="info" @click="loginOut">登出</el-button>
          </div></el-col
        >
      </el-row>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '60px' : '200px'">
        <div class="toggle" @click="isCollapse = !isCollapse">|||</div>
        <el-menu
          :default-active="`${$route.push}`"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#409eff"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          router
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in Menus"
            :key="item.id"
          >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + item1.path"
              v-for="item1 in item.children"
              :key="item1.id"
            >
              <i class="el-icon-menu"></i>
              <span slot="title">{{ item1.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!-- 主体内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { getMenuList } from '@/http/api'
export default {
  name: 'Home',
  components: {},
  data() {
    return {
      isCollapse: false,
      // 左侧菜单栏数据
      Menus: []
    }
  },
  created() {
    // 获取左侧菜单数据
    this.getMenuList()
  },
  mounted() {},
  methods: {
    // 封装saiox请求左侧菜单数据
    async getMenuList() {
      const res = await getMenuList()
      // console.log(res)
      this.Menus = res
    },

    // 登出功能
    loginOut() {
      // 清除本地token
      sessionStorage.removeItem('token')
      // 跳转到登录页面
      this.$router.push('/login')
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  color: #fff;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #333744;
  color: #333;
  .el-menu-item {
    padding: 0;
  }
  .el-menu {
    padding: 0;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
}
.toggle {
  height: 30px;
  line-height: 30px;
  color: #fff;
  background-color: #4a5064;
  cursor: pointer;
  text-align: center;
}
</style>
